package org.jiuling.request.http.handle;

import org.jiuling.basics.converter.StringConvert;
import org.jiuling.basics.enums.HttpResponseStatusEnum;
import org.jiuling.request.exception.RequestRuntimeException;
import org.jiuling.request.http.model.HttpResponse;

/**
 * 响应处理
 * @author 紫灵
 * @date 2024年11月25日 00时19分09秒
 */
public class ResponseHandle {

    /**
     * 错误处理
     * @param httpResponse http响应
     */
    public static void errorHandle(HttpResponse httpResponse){
        HttpResponseStatusEnum httpResponseStatus = httpResponse.getHttpResponseStatus();
        if (httpResponseStatus != HttpResponseStatusEnum.OK) {
            throw new RequestRuntimeException(
                    StringConvert.format("响应状态码：{}，响应信息：{}，响应描述：{}","{}",
                            httpResponseStatus.getStatus(),
                            httpResponseStatus.getMsg(),
                            httpResponseStatus.getDescribe())
            );
        }
    }

}
